package org.ping.Container;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;

import org.ping.Tool.LogUtil;

/**
 * @author PING
 * 这是一个过滤器，现在的功能有：
 * 1.设置访问servlet的编码格式
 */
@WebFilter("/*")
public class MyServletFilet implements Filter{
	@Override
	public void init(FilterConfig arg0) throws ServletException {
		LogUtil.getLogUtil(this).showlog("过滤器开始运行！");
	}

	@Override
	public void destroy() {
		LogUtil.getLogUtil(this).showlog("过滤器结束运行!");
	}

	@Override
	public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain)
			throws IOException, ServletException {
		//设置编码格式
		
		req.setCharacterEncoding("UTF-8");
		resp.setCharacterEncoding("UTF-8");
		chain.doFilter(req, resp);
	}
	
}
